{% extends 'base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}
{% from 'macros.html' import post_card, user_card with context %}

{% block title %}搜索: {{ q }}{% endblock %}

{% block content %}
    <div class="page-header">
        <h1>关键字: {{ q }}</h1>
    </div>
    <div class="row">
        <div class="col-md-3">
            <div class="nav nav-pills flex-column" role="tablist" aria-orientation="vertical">
                <a class="nav-item nav-link {% if category == 'post' %}active{% endif %}"
                   href="{{ url_for('main.search', q=q, category='post') }}">文章</a>
                <a class="nav-item nav-link {% if category == 'user' %}active{% endif %}"
                   href="{{ url_for('main.search', q=q, category='user') }}">用户</a>
            </div>
        </div>
        <div class="col-md-9">
            {% if results %}
                <h5>{{ results|length }} 条结果</h5>
                {% for item in results %}
                    {% if category == 'post' %}
                        {{ post_card(item) }}
                    {% else %}
                        {{ user_card(item) }}
                    {% endif %}
                {% endfor %}

            {% else %}
                <h5 class="tip">没有任何结果!</h5>
            {% endif %}
        </div>
    </div>
    {% if results %}
        <div class="page-footer">
            {{ render_pagination(pagination, align='right') }}
        </div>
    {% endif %}
{% endblock %}
